<template>
  <div>
    <TopFilter :list="partFilterList" :cols="3" :labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <FilterTable ref="partTable" :columns="partColumns" :isSelectColumn="false" :dataSource="listResult" :datakey="'rows'" :onColumnsChange="columns => (this.partColumns = columns)">
      <template slot="controls">
        <el-button size="small" type="primary">导出</el-button>
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'salesManage',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      partFilterList: this.createPartFilterList(),
      // fetchApi:'',
      // fetchParams: { xhrAbort: false },
      listResult: [],
      partColumns: this.createPartColumns()
    };
  },

  methods: {
    createPartFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '库位代码',
          fieldName: 'STORAGE_POSITION'
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME'
        },
        {
          type: 'INPUT',
          label: '拼音代码',
          fieldName: 'SPELL_CODE'
        },
        {
          type: 'SELECT',
          label: '配件类别',
          fieldName: 'PART_GROUP_CODE',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '配件车型组',
          fieldName: 'PART_MODEL_GROUP_CODE_SET',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '九大类',
          fieldName: 'PART_MAIN_TYPE',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '停用状态',
          fieldName: 'isStop',
          itemList: this.createDictList('1004')
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'REMARK'
        }
      ];
    },
    createPartColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true
        },
        {
          title: '配件类别',
          dataIndex: 'PART_GROUP_CODE',
          sorter: true
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '配件车型组集',
          dataIndex: 'PART_MODEL_GROUP_CODE_SET',
          sorter: true
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true
        },
        {
          title: '销售价',
          dataIndex: 'SALES_PRICE',
          sorter: true
        },
        {
          title: '终端建议零售价格',
          dataIndex: 'INSURANCE_PRICE',
          sorter: true
        },
        {
          title: '计量单位名称',
          dataIndex: 'UNIT_NAME',
          sorter: true
        },
        {
          title: '借进数量',
          dataIndex: 'BORROW_QUANTITY',
          sorter: true
        },
        {
          title: '借出数量',
          dataIndex: 'LEND_QUANTITY',
          sorter: true
        },
        {
          title: '销售限价',
          dataIndex: 'LIMIT_PRICE',
          sorter: true
        },
        {
          title: '预留量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true
        },
        {
          title: '九大类',
          dataIndex: 'PART_MAIN_TYPE',
          sorter: true
        },
        {
          title: '产地',
          dataIndex: 'PRODUCTING_AREA',
          sorter: true
        },
        {
          title: '可用库存',
          dataIndex: 'USERBLE_QUANTITY',
          sorter: true
        },
        {
          title: '最大库存',
          dataIndex: 'MAX_STOCK',
          sorter: true
        },
        {
          title: '最小库存',
          dataIndex: 'MIN_STOCK',
          sorter: true
        },
        {
          title: '最小包装数',
          dataIndex: 'MIN_PACKAGE',
          sorter: true
        },
        {
          title: '最新入库日期',
          dataIndex: 'LAST_STOCK_IN',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '最新出库日期',
          dataIndex: 'LAST_STOCK_OUT',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '建档日期',
          dataIndex: 'FOUND_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '是否停用',
          dataIndex: 'PART_STATUS',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.PART_STATUS, '1004')}</span>;
          }
        },
        {
          title: '订货周期',
          dataIndex: 'LEAD_TIME',
          sorter: true
        },
        {
          title: '拼音代码',
          dataIndex: 'SPELL_CODE',
          sorter: true,
          filter: true
        },
        {
          title: '替代配件',
          dataIndex: 'OPTION_NO',
          sorter: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true
        }
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  },
  mounted() {
    this.BaseTable = this.$refs.partTable.$refs.pageTable;
    let list = {
      STORAGE_CODE: 'OEM库',
      STORAGE_POSITION_CODE: 'E06A01',
      PART_GROUP_CODE: '',
      PART_NO: 'VC3D1LB',
      PART_NAME: '防冻液',
      PART_MODEL_GROUP_CODE_SET: '',
      STOCK_QUANTITY: 120.0,
      SALES_PRICE: 149.41,
      INSURANCE_PRICE: 0.0,
      UNIT_NAME: '个',
      BORROW_QUANTITY: 1.0,
      LEND_QUANTITY: 2.0,
      LIMIT_PRICE: 3.0,
      LOCKED_QUANTITY: 2,
      PART_MAIN_TYPE: '',
      PRODUCTING_AREA: '',
      USERBLE_QUANTITY: 8,
      MAX_STOCK: 10,
      MIN_STOCK: 2,
      MIN_PACKAGE: 1,
      LAST_STOCK_IN: '2018-01-22 09:57:59',
      LAST_STOCK_OUT: '2018-03-12 12:03:51',
      FOUND_DATE: '2018-09-18 14:17:55',
      PART_STATUS: 10041001,
      LEAD_TIME: '',
      SPELL_CODE: 'PYZ',
      OPTION_NO: '',
      REMARK: '123'
    };
    this.listResult = [list];
  }
};
</script>

<style scoped lang="less"></style>
